from .base import db
from datetime import datetime

class DictionaryItem(db.Model):
    __tablename__ = 'dictionary_item'

    id = db.Column(db.Integer, primary_key=True)
    type_code = db.Column(db.String(64), db.ForeignKey('dictionary_type.code'), nullable=False, comment='所属类型编码')
    value = db.Column(db.String(64), nullable=False, comment='选项值')
    label = db.Column(db.String(128), nullable=False, comment='选项显示文本')
    sort_order = db.Column(db.Integer, default=0, comment='排序')
    status = db.Column(db.SmallInteger, default=1, comment='状态 1启用 0禁用')
    remark = db.Column(db.String(255), comment='备注')
    create_time = db.Column(db.DateTime, default=datetime.utcnow)
    update_time = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def to_dict(self):
        return {
            'id': self.id,
            'type_code': self.type_code,
            'value': self.value,
            'label': self.label,
            'sort_order': self.sort_order,
            'status': self.status,
            'remark': self.remark,
            'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S') if self.create_time else None,
            'update_time': self.update_time.strftime('%Y-%m-%d %H:%M:%S') if self.update_time else None
        } 